Previous Book Contents Book Index Next

Inside Macintosh: AppleScript Language Guide / Part 1 - Introducing AppleScript
Chapter 2 - Overview of AppleScript / Expressions


Variables

When AppleScript encounters a variable in a script, it evaluates the variable by getting its value. To create a variable, simply assign it a value:

copy "Mitch" to myName
The Copy command takes the data--the string "Mitch"--and puts it in the variable myName. You can accomplish the same thing with the Set command:

set myName to "Mitch"
Statements that assign values to variables are known as assignment statements.

You can retrieve the value in a variable with a Get command. Run the following script and then display the result:

set myName to "Mitch"get myName
You see that the value in myName is the value you stored with the Set command.

You can change the value of a variable by assigning it a new value. A variable can hold only one value at a time. When you assign a new value to an existing variable, you lose the old value. For example, the result of the Get command in the following script is "Pegi".

set myName to "Mitch"set myName to "Pegi"get myName
AppleScript does not distinguish uppercase letters from lowercase variables in variable names; the variables myName, myname, and MYNAME all represent the same value.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996